package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.RenewContractNotice;
import com.amsp.oa.oademo.mapper.RenewContractNoticeMapper;
import com.amsp.oa.oademo.service.RenewContractNoticeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class RenewContractNoticeServiceImpl extends ServiceImpl<RenewContractNoticeMapper, RenewContractNotice>
        implements RenewContractNoticeService {

    @Override
    public IPage<RenewContractNotice> getPage(Page<RenewContractNotice> page, String applicant) {
        LambdaQueryWrapper<RenewContractNotice> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(applicant)) {
            wrapper.like(RenewContractNotice::getApplicant, applicant);
        }
        wrapper.orderByDesc(RenewContractNotice::getCreateTime);
        return baseMapper.selectPage(page, wrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveOrUpdateBatchTran(List<RenewContractNotice> notices) {
        return super.saveOrUpdateBatch(notices);
    }
}